package com.intelligentmeterreadingsys.waterlist.querywaterlist.activity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.intelligentmeterreadingsys.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListViewAdapter extends BaseAdapter {

	private static Map<Integer,View> m=new HashMap<Integer,View>();
	
	private List<String> items;
	private LayoutInflater inflater;
	
	public ListViewAdapter(List<String> items, Context context) {
		super();
		this.items = items;
		this.inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		
		return items.size();
	}

	@Override
	public Object getItem(int position) {
		
		return items.get(position);
	}

	@Override
	public long getItemId(int position) {
		
		return position;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup arg2) {
		
		contentView=m.get(position);
		if(contentView==null){
			contentView=inflater.inflate(R.layout.listview_item, null);
			TextView text=(TextView) contentView.findViewById(R.id.list_item_text);
			text.setText(items.get(position));
		}
		m.put(position, contentView);
		return contentView;
	}
	
	/**
	 * 删除所有数据
	 */
	public void removeItem(){
	   items.clear();
	   m.clear();
	}
	/**
	 * 添加数据
	 * @param item
	 */
	public void addItem(String item) {  
		
        items.add(item);  
    }

	

}

